package com.example.wordlistdemo;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class WordGroupsAdapter extends RecyclerView.Adapter<WordGroupsAdapter.WordGroupViewHolder> {

    private List<List<WordEntity>> wordGroups;
    private OnItemClickListener listener;

    public WordGroupsAdapter(List<List<WordEntity>> wordGroups, OnItemClickListener listener) {
        this.wordGroups = wordGroups;
        this.listener = listener;
    }

    @NonNull
    @Override
    public WordGroupViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_group, parent, false);
        return new WordGroupViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull WordGroupViewHolder holder, int position) {
        List<WordEntity> wordGroup = wordGroups.get(position);
        // 设置单词组的内容
        holder.textViewGroupName.setText("Group " + (position + 1));
        // 可以根据需要设置其他内容
    }

    @Override
    public int getItemCount() {
        return wordGroups.size();
    }

    class WordGroupViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        TextView textViewGroupName;

        WordGroupViewHolder(@NonNull View itemView) {
            super(itemView);
            textViewGroupName = itemView.findViewById(R.id.text_view_group_name);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (listener != null) {
                listener.onItemClick(getAdapterPosition());
            }
        }
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }
}

